<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/dataTables.bootstrap.min.css">
<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
</head>
<body>
    <div>
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <div>
                <header style="height: 100%">
                    <div align="left">
	                    <table style="width: 100%">
	                   		<tr>
	                   			<td>
		                   			<form class="form-inline" onsubmit="return false">
										<div class="form-group">
											公司名称：
											<input id="orgName" type="text" class="form-control" placeholder="id">
											<button id="searchBt" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe615;</i>搜索</button>
										</div>
									</form>
	                   			</td>
	                   			<!-- <td align="right">
	                   				<button class="layui-btn layui-btn-sm" onclick="location.href='addOrg.html'">
                                      <i class="layui-icon">&#xe608;</i> 添加
                                    </button>
	                   			</td> -->
	                   		</tr> 
	                    </table>
					</div>
                </header>
                
                <div>
                    <div class="widget-body no-padding">
                        <table id="dt-table" class="table table-striped table-bordered table-hover" style="width:100%">
                            <thead>
                                <tr>
                                </tr>                       
                                <tr>
									<th>公司ID</th>
									<th>公司编码</th>
									<th>公司类型</th>
									<th>公司名称</th>
									<th>公司描述</th>
									<th>公司状态</th>
									<th>创建人</th>
									<th>创建时间</th>
									<th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>
<script type="text/javascript" src="../../js/dict.js"></script>
<script type="text/javascript">
var pers = checkPermission();
var userStatus = showDictSelect("status", "userStatus", true);
var example;
function init(){
	example = 
    	$('#dt-table').DataTable({
        	"searching": false,
        	"processing": false,
        	"serverSide" : true,
        	"ordering" : false,
        	"language": {
                "url": urlRootPrefix + "/js/plugin/datatables/Chinese.lang"
            },
        	"ajax": {
        		"url" : urlRootPrefix + "/orgs",
        		"type":"get",
        		"data":function(d){
    				d.orgName = $("#orgName").val();
    			},
    			"dataSrc" : function(data) {
  				  //自定义错误拦截
   		          if(!data.success && !isNotBlank(data.recordsTotal)){
   		           	layer.msg(data.msg, {shift: -1, time: 3000}, function(){});
   					return [];
   				  }
   		          return data.data;
    			} 
        	},
        	"dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-10 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-10' p v>>",	
            "columns": [
				{"data" : "indexId", "defaultContent" : ""},
				{"data" : "orgCode", "defaultContent" : ""},
				{"data" : "orgTypeName", "defaultContent" : ""},
				{"data" : "orgName", "defaultContent" : ""},
				{"data" : "orgDes", "defaultContent" : ""},
				{ 
                	"data": "orgStatus", 
                	"defaultContent": "",
                	"render": function (data, type, row) {
                    	return userStatus[data];
                  	}
                },
				{"data" : "createUserName", "defaultContent" : ""},
				{"data" : "createTime", "defaultContent" : ""},
				{"data": "", 
					"defaultContent": "",
					"orderable":false,
			        "render": function (data, type, row) {
             		           var id = row['orgId'];
             		           var href = "updateOrg.html?id=" + id;
                                var edit = buttonEdit(href, "", pers);
             		           var del = buttonDel(id, "", pers);
                                return edit + del;
               	            }		
				},
                
            ],
           "order": [[ 0, "asc" ]]
        } );
}

layui.use('layer', function(){
    var layer = layui.layer;
});

function del(id){
	layer.confirm('确定要删除吗？', {
        btn : [ '确定', '取消' ]
    }, function() {
    	$.ajax({
            type : 'delete',
            url : urlRootPrefix + '/orgs/'+id,
            success : function(data) {
            	if(!data.success){
					layer.msg(data.msg, {shift: -1, time: 3000}, function(){});
					$("button[type='submit']").removeAttr("disabled");
					return;
				}
                example.ajax.reload();
                layer.msg("删除成功");
            }
        });
        
        layer.close(1);
    });
}

$("#searchBt").click(function(){
	example.ajax.reload();
});

init();
</script>
